import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/my_webview/my_webview_page.dart';
import 'package:yysk_app/routes/global_controller.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/utils/js_tool.dart';
import 'package:yysk_app/widget/button_widget.dart';
import 'package:yysk_app/widget/checkbox_widget.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'open_wallet_controller.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';

class OpenWalletPage extends GetView<OpenWalletController> {
  static const path = '/openWallet';
  const OpenWalletPage({super.key});

  @override
  Widget build(BuildContext context) {
    double top = MediaQuery.of(context).padding.top;
    return Scaffold(
      // appBar: CustomAppBar(
      //   title: '开通钱包',
      //   context: context,
      //   actions: const [],
      // ),
      body:SafeArea(top: false,child: Obx(()=>     Container(
        color: AppColors.backgroundColorLightGrey,
        child: Stack(
          children: [
            //添加背景色，代码如下：
            SizedBox(
              width: context.width,
              child: ImageAssetWidget(
                width: double.infinity,
                height: 173.px,
                imageUrl: 'static/images/wallet/top_bg.png',
              ),
            ),
            Padding(
              padding: EdgeInsets.fromLTRB(0, top, 0, 24.px),
              child: Column(
                children: [
                  CustomAppBar2(title: '开通钱包', context: context),
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 24),
                      child: ListView(
                        children: [
                          const SizedBox(height: 24),
                          _inputItem('姓名', '请输入姓名',controller.infoDetail.value?.name??''),
                          _inputItem('身份证', '请输入身份证号',controller.infoDetail.value?.cardId??''),
                          Text(
                            '证件期限类型',
                            style: TextStyle(
                              color:  AppColors.fontColorBlack,
                              fontSize: 16.px,
                              // fontWeight: FontWeight.bold,
                              fontFamily: 'CustomPINGFANG',
                            ),
                          ),
                          _buildCartTypeTime(
                            context: context,
                            OpenWalletController: controller,
                          ),
                          SizedBox(height: 16.px),
                          Text(
                            '证件有效期',
                            style: TextStyle(
                              color:  AppColors.fontColorBlack,
                              fontSize: 16.px,
                              // fontWeight: FontWeight.bold,
                              fontFamily: 'CustomPINGFANG',
                            ),
                          ),
                          _buildCartType(
                            context: context,
                            OpenWalletController: controller,
                          ),
                          SizedBox(height: 16.px),
                          _inputItem('手机号', '请输入手机号',controller.infoDetail.value?.userTel??''),
                          const SizedBox(height: 32),
                          const Text('注意事项', style: TextStyle(color: AppColors.fontColorBlack, fontSize: 18)),
                          const SizedBox(height: 8),
                          const Text(
                            '1、为保证平台用户的资金安全，平台引入透明的第三方机构监管资金；\n'
                                '2、开通第三方提现资金管理钱包，需要绑定与平台注册名一致的身份信息及银行卡信息；\n'
                                '3、应第三方监管要求，用户快捷支付到账周期为D+1；用户提现至银行卡时统一由第三方机构审核，到账周期以第三方机构为准。',
                            style: TextStyle(color: AppColors.fontColorGreyLight, fontSize: 12),
                          ),
                          const SizedBox(height: 24),


                        ],
                      ),
                    ),
                  ),

                  Column(
                    children: [
                      Obx(() => Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          CheckboxWidget(
                            onChanged: (v) => controller.agree.value = v,
                            checked: controller.agree.value,
                            size: 12,
                          ),
                          const Text('我已阅读理解并同意', style: TextStyle(color: AppColors.fontColorBlack, fontSize: 12)),
                          GestureDetector(
                            onTap: () {
                              final GlobalController globalController = Get.find();
                              final staticInfo = globalController.staticInfo.value;
                              Get.toNamed(
                                '${MyWebViewPage.path}?url=${Uri.encodeComponent(staticInfo?.hnPayAgreement ?? '')}',
                                arguments: {
                                  'url': Uri.encodeComponent(
                                    staticInfo?.hnPayAgreement ?? '',
                                  ),
                                },
                              );
                            },
                            child: Text('《${controller.channel == 'HUIFU'?'汇付' : '智付'}支付服务协议》', style: TextStyle(color: AppColors.fontColorGreen, fontSize: 12)),
                          ),
                        ],
                      )),
                      const SizedBox(height: 16),
                      ButtonWidget(
                        label: '确定开通钱包',
                        height: 54,
                        width: 322,
                        fontSize: 22.px,
                        imageBg: 'static/images/btm.png',
                        contentType: ContentType.other,
                        onPressed: controller.submit,
                      )


                    ],
                  )
                ],
              ),
            ),
          ],
        ),
      )),
  )
    );
  }

  Widget _inputItem(String label,  String hint,String value) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(label, style:  TextStyle(color: AppColors.fontColorBlack, fontSize: 16.px,fontFamily: 'CustomPINGFANG')),
         SizedBox(height: 20.px),
         Text(value, style:  TextStyle(color: AppColors.fontColorBlack, fontSize: 16.px)),
          SizedBox(height: 9.px),
          Container(
            width: 344.px,
            height: 1.px,
            color: AppColors.backgroundColorGreyF2,
          )
        ,
         SizedBox(height: 30.px),
      ],
    );
  }
    _buildCartTypeTime({
    required BuildContext context,
    required OpenWalletController OpenWalletController,
  }) {
    return Obx(
      () => Container(
        width: context.width,
        height: 45.px,
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              width: 1.px,
              color: Color.fromRGBO(242, 242, 242, 1),
            ),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              child: Row(
                children: [
                  CheckboxWidget(
                    checked: !controller.isLong.value,
                    size: 12.px,
                    onChanged: (value) {
                      controller.isLong.value = false;
                      controller.certEndDate.value = '';
                    },
                  ),
                  Text(
                    '非长期有效',
                    style: TextStyle(
                      fontSize: 16.px,
                      color: AppColors.fontColorBlack,
                      fontFamily: 'CustomPINGFANG',
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(width: 28.px),
            Container(
              child: Row(
                children: [
                  CheckboxWidget(
                    checked: controller.isLong.value,
                    size: 12.px,
                    onChanged: (value) {
                      controller.isLong.value = true;
                      controller.certEndDate.value = '20990101';
                    },
                  ),
                  Text(
                    '长期有效',
                    style: TextStyle(
                      fontSize: 16.px,
                      color: AppColors.fontColorBlack,
                      fontFamily: 'CustomPINGFANG',
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
_buildCartType({
    required BuildContext context,
    required OpenWalletController OpenWalletController
  }) {
    return Container(
      width: context.width,
      height: 45.px,
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            width: 1.px,
            color: Color.fromRGBO(242, 242, 242, 1),
          ),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          controller.certBeginDate.value==''? GestureDetector(
            onTap: (){
              controller.pickValidityDate(0);
            },
            child: Text(
            '起始时间',
            style: TextStyle(
              fontSize: 16.px,
              color: AppColors.fontColorGreenA9,
              fontFamily: 'CustomPINGFANG',
            ),
          ),
          ): GestureDetector(
                  onTap: (){
                   
              controller.pickValidityDate(0);
            },
            child: Text(
            controller.certBeginDate.value,
            style: TextStyle(
              fontSize: 16.px,
              color: AppColors.fontColorBlack,
              fontFamily: 'CustomPINGFANG',
            ),
          ),
          ),
          Text(
            '   -    ',
            style: TextStyle(
              fontSize: 16.px,
              color: AppColors.fontColorGreenA9,
              fontFamily: 'CustomPINGFANG',
            ),
          ),
          controller.certEndDate.value==''?GestureDetector(
            onTap: (){
               if(controller.isLong.value==true){
                      return;
                    }
              controller.pickValidityDate(1);
            },
            child: Text(
            '截止日期',
            style: TextStyle(
              fontSize: 16.px,
              color: AppColors.fontColorGreenA9,
              fontFamily: 'CustomPINGFANG',
            ),
          ),
          ):GestureDetector(
               onTap: (){
                  if(controller.isLong.value==true){
                      return;
                    }
              controller.pickValidityDate(1);
            },
            child: Text(
            controller.certEndDate.value,
            style: TextStyle(
              fontSize: 16.px,
              color: AppColors.fontColorBlack,
              fontFamily: 'CustomPINGFANG',
            ),
          ),
          ),
        ],
      ),
    );
  }

}
